package com.hsylient.javase.chapter05.demo12;

import lombok.SneakyThrows;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

/**
 * 结果是：Student{name='hsylient', age=22, id=null}
 * 表明transient关键字生效了，id字段确实没有参与序列化
 */
public class MyObjectInputStream {

    @Test
    @SneakyThrows
    public void testInput() {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("student.txt"));
        Object object = objectInputStream.readObject();
        System.out.println(object);
        objectInputStream.close();
    }
}
